package com.project.controller;


import com.project.entity.SysBusinessInfo;
import com.project.entity.SysStore;
import com.project.entity.SysUser;
import com.project.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/*
 * @Author(作者) 王崇人
 * @Description(类的描述): 商铺用户前端控制器
 *：@version（开发的版本）：1.0
 * @Date(创建时间)：2021-10-08
 */
@RestController
@RequestMapping("/sys-user")
public class SysUserController {
    @Autowired
    private ISysUserService sysUserService;

    @GetMapping("addStore/{userId}/{bAddress}/{bDoorimage}/{bCropname}" +
            "/{bCropCardImageFront}/{bCropCardImageRevese}/{bCharterImage}" +
            "/{bLicenceImage}/{bOpenArea}/{bregistrationtime}/{storeName}/{pName}/{pNum}/{storeCode}")
    public String addStore(@PathVariable("userId") Integer userId, @PathVariable String bAddress,
                           @PathVariable String bDoorimage,
                           @PathVariable String bCropname,
                           @PathVariable String bCropCardImageFront,
                           @PathVariable String bCropCardImageRevese,
                           @PathVariable String bCharterImage,
                           @PathVariable String bLicenceImage,
                           @PathVariable String bOpenArea,
                           @PathVariable String bregistrationtime,
                           @PathVariable Integer storeId,
                           @PathVariable Integer principal,
                           @PathVariable String storeName,
                           @PathVariable String pName,
                           @PathVariable String pNum,
                           @PathVariable String storeCode
    ) {
        if (sysUserService.findById(userId) != null) {
            return "您已经注册过了";
        }
        SysUser sysUser = new SysUser();
        sysUser.setUserId(userId);
        SysBusinessInfo sysBusinessInfo = new SysBusinessInfo();
        sysBusinessInfo.setBAddress(bAddress);
        sysBusinessInfo.setBDoorimage(bDoorimage);
        sysBusinessInfo.setBCropname(bCropname);
        sysBusinessInfo.setBCropCardImageFront(bCropCardImageFront);
        sysBusinessInfo.setBCropCardImageRevese(bCropCardImageRevese);
        sysBusinessInfo.setBCharterImage(bCharterImage);
        sysBusinessInfo.setBLicenceImage(bLicenceImage);
        sysBusinessInfo.setBOpenArea(bOpenArea);
        sysBusinessInfo.setBregistrationtime(bregistrationtime);
        sysBusinessInfo.getStore().setPkStoreid(storeId);
        sysBusinessInfo.getPrincipal().setPkPrincipalid(principal);
        sysUserService.addStore(sysUser, sysBusinessInfo);
        sysUserService.add(storeName, bDoorimage, storeCode, userId, pName, pNum);
        return "ok";
    }

    @GetMapping("findById/{userId}")
    public SysUser findById(@PathVariable Integer userId) {
        return sysUserService.findById(userId);
    }

    @GetMapping("showStore/{userId}")
    public List<SysStore> showStore(@PathVariable Integer userId) {
        return sysUserService.showStore(userId);
    }
}
